package main

import (
	"gitee.com/d-fw/gofw-cache/conf"
	"log"
	"net/http"
	"strings"

	"gitee.com/d-fw/gofw-cache/internal/cache"
	"gitee.com/d-fw/gofw-cache/internal/remote"
	"gitee.com/d-fw/gofw-cache/pkg/logger"
)

// Single deployment
func main() {
	// init log
	logger.InitLog()
	// init cfg
	cacheCfg, _ := conf.InitCfg()
	// init cache
	c := cache.NewCache(cacheCfg.CacheName, cacheCfg.Capacity)
	httpPool := remote.NewHttpPool(cacheCfg.SelfAddr)
	httpPool.SetClusterAddr(cacheCfg.ClusterAddr[0])
	// init timer
	cache.SaveCache()
	// register nodes
	c.RegisterNodes(httpPool)
	log.Println("gofw-cache is runnning...", cacheCfg.SelfAddr)
	log.Fatal(http.ListenAndServe(":"+strings.Split(cacheCfg.SelfAddr, ":")[1], httpPool))
}
